package com.zlx.rulemk.demos.drools;

import com.zlx.rulemk.demos.drools.beans.DataBean;
import org.apache.commons.io.FileUtils;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.io.File;
import java.io.IOException;

public class DroolsDemo3 {

    public static void main(String[] args) throws IOException {

        // String drlString = FileUtils.readFileToString(new File("rule_engine/rules/rule2.drl"), "utf-8");
        String drlString = FileUtils.readFileToString(new File("rule_engine/rules/demo1.drl"), "utf-8");

        KieHelper kieHelper = new KieHelper();

        kieHelper.addContent(drlString, ResourceType.DRL);
        KieSession kieSession = kieHelper.build().newKieSession();

        DataBean dataBean = new DataBean("22","");
        // 调用规则引擎
        kieSession.insert(dataBean);

        kieSession.fireAllRules();
        kieSession.dispose();

        System.out.println("drools result>>>>： " + dataBean);


    }
}